import requests
from lxml import etree
import os

folder_name = "./我写的代码犯法吗直播课件/"
if not(os.path.exists(folder_name)):
    os.mkdir(folder_name)

file_name = "./我写的代码犯法吗直播课件.html"
with open(file_name, 'r', encoding="utf-8") as f:
    my_str = f.read()

# print(my_str)
html = etree.HTML(my_str)

links = html.xpath('//p//img[@class="xzx_center"]/@src')
names = html.xpath('//p//img[@class="xzx_center"]/@alt')
# print(links, names)

for i in range(len(links)):
    res = requests.get(links[i])
    with open(os.path.join(folder_name, names[i]), 'wb') as f:
        f.write(res.content)
        
print("下载完毕！")